// run: $exec < input
#include <iostream>
#include <queue>
#include <vector>

int n;

int main()
{
	std::cin >> n;
	std::priority_queue<int> pq;

	int my;
	std::cin >> my;
	for (int i = 1, x; i < n; i++) {
		std::cin >> x;
		pq.push(x);
	}

	int ans = 0;
	while (!pq.empty() && my <= pq.top()) {
		int x = pq.top(); pq.pop();
		my++; x--; ans++;
		pq.push(x);
	}
	std::cout << ans << '\n';
}

